print("hello,lua!")

for i=10,1,-1 do
    print(i)
end

print("#1")
func("mycmdline", 1, 2, 3, 4)

print("#2")
func("mycmdline", 1, "arg2", 3, 4, 5, 6)

print("#3")
func("mycmdline", 1, 2, 3, "last")

print("#4")
func(mycmdline, 1, 2, 3, 4, 5, 6, 7)

for i=0,10 do
    func("mycmdline", i, i, i, "last")
end

function f(x)  
    print("function")  
    return x*2  
end  
for i=1,f(5) do print(i)  
end

--打印数组a的所有值  
a = {"one", "two", "three"}
for i, v in ipairs(a) do
    print(i, v)
end 

days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}  
for i,v in ipairs(days) do  print(v) end 

--[[ 函数返回两个值的最大值 --]]
function max(num1, num2)

    if (num1 > num2) then
       result = num1;
    else
       result = num2;
    end
 
    return result;
 end
 -- 调用函数
 print("两值比较最大值为 ",max(10,4))
 print("两值比较最大值为 ",max(5,6))

 function average(...)
    result = 0
    local arg={...}    --> arg 为一个表，局部变量
    for i,v in ipairs(arg) do
       result = result + v
    end
    print("总共传入 " .. #arg .. " 个数")
    return result/#arg
 end
 
 print("平均值为",average(10,5,3,4,5,6))

 -- create error
 func_none 0 1 2 3

